var config=require('../config/index');

const mongoose = require('mongoose');
var connection;
module.exports.connect= function(cb){
    if(connection){
        return connection;
    }
    
    mongoose.connect(config.mongodb,function(err){
        if(err){
            console.error(err);
            
        }else{
            console.log('连接成功');
        }
        
    })
    
    connection= mongoose.connection;
    connection.on('error', console.error.bind(console, 'connection error:'));
    connection.once('open', function () {
        // we're connected!
        console.log('open')
    });
    return connection;
}